/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cryptography;

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;

/**
 *
 * @author John
 */
public class DiffieHellman {

    private static BigInteger primeNumber;
    private static BigInteger base;
    private static BigInteger quantity;
    private static BigInteger randBigInt;
    private static BigInteger key;
    

    public void initiate() {

        primeNumber = generatePrime();
        base = generateBase();
        quantity = generateQuantity(base, primeNumber);
    }

    public BigInteger getPrimeNumber() {

        return primeNumber;
    }

    public BigInteger getBase() {

        return base;
    }

    public BigInteger getQuantity() {

        return quantity;
    }

    private BigInteger generatePrime() {

        BigInteger primeNumb = BigInteger.probablePrime(512, new SecureRandom());

        return primeNumb;
    }

    private BigInteger generateBase() {

        BigInteger b = BigInteger.probablePrime(64, new Random());

        return b;
    }

    private BigInteger generateQuantity(BigInteger base, BigInteger primeNumber) {

        randBigInt = BigInteger.probablePrime(64, new Random());

        BigInteger quant = base.modPow(randBigInt, primeNumber);
        
        return quant;
    }

    public BigInteger calculateKey(BigInteger clientQuantity) {

    
        BigInteger key = clientQuantity.modPow(randBigInt, primeNumber);
        
        return key;
    }
}
